﻿using System;
using System.Collections.Generic;

namespace HarrisDesigns.Controls.dasBlogControls.Google.Reader
{
    public class Repository : JsonRepository<Feed>
    {
        private const string JsonRequestUrlFormat = "http://www.google.com/reader/public/javascript/user/{0}/state/com.google/broadcast?n={1}";

        private static DataStore<Feed> _dataStore;

        private int _maxItems = 10;

        public override DataStore<Feed> DataStore
        {
            get
            {
                if (_dataStore == null)
                {
                    _dataStore = new DataStore<Feed>();
                }
                return _dataStore;
            }
        }

        public int MaxItems
        {
            get { return _maxItems; }
            set { _maxItems = value; }
        }

        public override string GetJsonRequestUrl()
        {
            if (String.IsNullOrEmpty(UserIdentity))
                throw new ArgumentException("UserIdentity must be specified before constructing a request URL");
            if (MaxItems < 1)
                throw new ArgumentException("Cannot retrieve less than 1 items");
            return String.Format(JsonRequestUrlFormat, UserIdentity, MaxItems);
        }
    }
}